#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution1
{
public:
    int minOperations(vector<int>& nums, int x)
    {
        int sum = 0;
        for (auto e : nums) sum += e;
        int left = 0, right = 0, ret = 0, n = nums.size(), target = sum - x;
        sum = 0;
        while (right < n)
        {
            sum += nums[right];
            if (sum == target) ret = max(ret, right - left + 1);
            while (left<right&&sum > target)
            {
                sum -= nums[left];
                left++;
            }
            if (sum == target) ret = max(ret, right - left + 1);
            right++;
        }
        return ret == 0 ? -1 : n - ret;
    }
};
class Solution7
{
public:
    vector<int> findAnagrams(string s, string p)
    {
        if (p.size() > s.size()) return {};
        vector<int> v;
        int hash1[26] = { 0 }, hash2[26] = { 0 }, cnt = 0;
        for (auto& e : p) hash1[e - 'a']++;
        int left = 0, right = 0;
        while (right < p.size())
        {
            hash2[s[right] - 'a']++;
            if (hash2[s[right] - 'a'] <= hash1[s[right] - 'a']) cnt++;
            right++;
        }
        if (cnt == p.size()) v.push_back(0);
        while (right < s.size())
        {
            if (hash2[s[left] - 'a'] <= hash1[s[left] - 'a']) cnt--;
            hash2[s[left] - 'a']--;
            left++;
            hash2[s[right] - 'a']++;
            if (hash2[s[right] - 'a'] <= hash1[s[right] - 'a']) cnt++;
            if (cnt == p.size()) v.push_back(left);
            right++;
        }

        return v;
    }
};
class Solution66
{
public:
    int mySqrt(int x)
    {
        int left = 1, right = x, mid;
        while (left < right)
        {
            mid = left + (right - left) / 2;
            if (mid * mid > x) right = mid - 1;
            else if (mid * mid < x) left = mid;
            else return mid;

        }
        return mid;
    }
};
class Solution
{
public:
    int findMin(vector<int>& nums)
    {
        int left = 0, right = nums.size() - 1, mid;
        while (left < right)
        {
            mid = left + (right - left) / 2;
            if (nums[mid] < nums[mid + 1]) right = mid;
            else left = mid + 1;
        }
        return nums[left];
    }
};
int main()
{
    vector<int> v = { 2,3,4,5,1 };
    Solution().findMin(v);
	return 0;
}